package com.jane.adapter.categoryadapter;

import android.content.Context;
import android.support.v7.widget.LinearSmoothScroller;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jane.bean.ZBInnerCategoryBean;
import com.jane.gzzb.R;
import com.jane.utils.Utils;

import java.util.ArrayList;

/**
 * Created by Jane on 2016/11/14.
 */

public class ZBInnerCategoryAdapter extends BaseAdapter{
    private ArrayList<ZBInnerCategoryBean.CommentatorsBean.GameinfoBean> list;
    private Context context;

    public ZBInnerCategoryAdapter(ArrayList<ZBInnerCategoryBean.CommentatorsBean.GameinfoBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(list.get(position)!=null){
            if(convertView==null){
                convertView=View.inflate(context,R.layout.item_view_zb_inner_category,null);
                vh=new ViewHolder(convertView);
                convertView.setTag(vh);
            }else{
                vh= (ViewHolder) convertView.getTag();
            }
            if(list.get(position).getRawcoverimage()!=null){
                Utils.loadImage(vh.iv,list.get(position).getRawcoverimage());
            }
            vh.tv1.setText(list.get(position).getName());
            int viewers = list.get(position).getViewers();
            if(viewers>10000){
                int num=viewers/10000;
                vh.tv2.setText(num+"万人");
            }else{
                vh.tv2.setText(viewers+"人");
            }

            vh.tv3.setText(list.get(position).getTitle());
            vh.tv4.setText(list.get(position).getSourcename()+"·"+list.get(position).getCommentator());
        }else{
            convertView=new View(context);
        }
        return convertView;
    }
    static class ViewHolder{
        ImageView iv;
        TextView tv1,tv2,tv3,tv4;

        public ViewHolder(View view) {
            iv= (ImageView) view.findViewById(R.id.iv_item_view_zb_inner_category);
            tv1= (TextView) view.findViewById(R.id.tv1_item_view_zb_inner_category);
            tv2= (TextView) view.findViewById(R.id.tv2_item_view_zb_inner_category);
            tv3= (TextView) view.findViewById(R.id.tv3_item_view_zb_inner_category);
            tv4= (TextView) view.findViewById(R.id.tv4_item_view_zb_inner_category);
        }
    }
}
